package com.victor.interceptor;

import io.lettuce.core.dynamic.annotation.CommandNaming;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@Component
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        HttpSession session = request.getSession();
        String username = (String) session.getAttribute("username");
        String password = (String) session.getAttribute("password");

        if ("admin".equals(username) && "admin".equals(password)) {
            return true;
        }
        // 跳转到登录页面
        response.sendRedirect("/user/login");
        return false;
    }
}
